package com.itheima.health.controller;



import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.constants.MessageConstant;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Role;
import com.itheima.health.service.RoleService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;


@RestController
@RequestMapping("/role")
public class RoleController {
    @Reference
    private RoleService roleService;

    @RequestMapping("/add")
    public Result add(@RequestBody Role role) {
        try {
            roleService.add(role);
        } catch (Exception e) {
            return new Result(false, MessageConstant.FAIL);
        }
        return new Result(true, MessageConstant.SUCCESS);

    }
    @RequestMapping("/delete")
    public Result delete(@RequestBody Integer id) {
        try {
            roleService.delete(id);
        } catch (Exception e) {
            return new Result(false, MessageConstant.FAIL);
        }
        return new Result(true, MessageConstant.SUCCESS);

    }
    @RequestMapping("/update")
    public Result update(@RequestBody Role role) {
        try {
            roleService.update(role);
        } catch (Exception e) {
            return new Result(false, MessageConstant.FAIL);
        }
        return new Result(true, MessageConstant.SUCCESS);

    }
    @RequestMapping("/selectById")
    public Role selectById(@RequestBody Integer id) {
        try {
            return roleService.select(id);
        } catch (Exception e) {
            return null;
        }
    }
    @RequestMapping("/selectPage")
    public PageResult selectPage(@RequestBody QueryPageBean queryPageBean) {
        try {
            return roleService.selectPage(queryPageBean);
        } catch (Exception e) {
            return null;
        }

    }
    @RequestMapping("/selectAll")
    public List<Role> selectAll() {
        try {
            return roleService.selectAll();
        } catch (Exception e) {
            return null;
        }
    }
}
